package ar.edu.uba.fi.jmit.graphvisualizer.server.service;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import ar.edu.uba.fi.jmit.graphvisualizer.client.DynamicMenuService;
import ar.edu.uba.fi.jmit.graphvisualizer.receiver.DynamicMenuObserverImpl;

public class DynamicMenuServiceImpl extends AbstractServiceImpl implements DynamicMenuService {

	private static final long serialVersionUID = 6241152187753539368L;

	@Override
	public Boolean hasUpdate(Map<String, List<String>> applicationMonitorsClient) {
		Map<String, List<String>> applicationMonitorsServer = DynamicMenuObserverImpl.getInstance().getApplicationMonitors();
		if (applicationMonitorsServer.keySet().size() != applicationMonitorsClient.keySet().size())
			return true;
		for (String key : applicationMonitorsServer.keySet()) {
			List<String> monitors = applicationMonitorsClient.get(key);
			if (monitors == null)
				return true;
			if (monitors.size() != applicationMonitorsServer.get(key).size())
				return true;
		}
			
		return false;
	}
	
	@Override
	public Map<String, List<String>> tree() {
		return DynamicMenuObserverImpl.getInstance().getApplicationMonitors();
	}

	@Override
	public Map<String, Serializable> getData(String appName, String monName) {
		logger.debug("Getting data for application " + appName + " and monitor name " + monName);
		return DynamicMenuObserverImpl.getInstance().getData(appName, monName);
	}
}
